// Copyright 2022 jeff.li. and/or its affiliates.

#pragma once

#include <tbir/runtime/container.h>
#include <tbir/runtime/ft_container.h>
#include <tbir/runtime/object.h>
#include <tbir/runtime/py_args.h>
#include <tbir/runtime/runtime_value.h>
#include <tbir/runtime/type_helper_macros.h>

namespace tbir::runtime {

    namespace {

        template<typename T>
        struct remove_runtime_view {
            using type = T;
        };

        template<>
        struct remove_runtime_view<string_view> {
            using type = String;
        };

        template<>
        struct remove_runtime_view<unicode_view> {
            using type = Unicode;
        };

        template<>
        struct remove_runtime_view<RTView> {
            using type = RTValue;
        };

    }  // namespace

/******************************************************************************
 * fused list ops
 *****************************************************************************/
    template<typename... Args>
    TURBO_FORCE_INLINE auto kernel_list_fused_repeat_one(Args &&... args) {
        return List::repeat_one(std::forward<Args>(args)...);
    }

    TURBO_FORCE_INLINE auto kernel_list_fused_repeat_many(
            const std::initializer_list<List::value_type> &values, int64_t times) {
        return List::repeat_many(values, times);
    }

    template<typename T>
    TURBO_FORCE_INLINE auto kernel_ft_list_fused_repeat_one(T &&value, int64_t times) {
        using T_TYPE = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
        using ElementType = typename remove_runtime_view<T_TYPE>::type;
        return FTList<ElementType>::repeat_one(std::forward<T>(value), times);
    }

    template<typename T>
    TURBO_FORCE_INLINE auto kernel_ft_list_fused_repeat_many(
            const std::initializer_list<T> &values, int64_t times) {
        using T_TYPE = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
        using ElementType = typename remove_runtime_view<T_TYPE>::type;
        return FTList<ElementType>::repeat_many(values, times);
    }

}  // namespace tbir::runtime
